package com.dm.adapter;

import static com.dm.DmActivity.defultType;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dm.R;

public class ListTypeAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<String> list;
    private LayoutInflater inflater = null;

    public ListTypeAdapter(Context context, ArrayList<String> list) {
	this.context = context;
	this.list = list;
	inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
	return list.size();
    }

    @Override
    public Object getItem(int position) {
	return list.get(position);
    }

    @Override
    public long getItemId(int position) {
	return 0;
    }

    @Override
    public View getView(int position, View convertView, final ViewGroup parent) {
	ViewHolder holder = null;
	if (convertView == null) {
	    holder = new ViewHolder();
	    convertView = inflater.inflate(R.layout.item_lytype, null);
	    holder.lytype = (TextView) convertView.findViewById(R.id.lytype);
	    holder.ib = (ImageView) convertView.findViewById(R.id.ib);
	    convertView.setTag(holder);
	} else {
	    holder = (ViewHolder) convertView.getTag();
	}
	holder.lytype.setText(list.get(position));
	if (position == 0) {
	    holder.ib.setVisibility(View.GONE);
	} else if (position >= defultType.length) {
	    holder.ib.setVisibility(View.VISIBLE);
	}
	return convertView;
    }

    static class ViewHolder {

	TextView lytype;
	ImageView ib;
    }
}
